What is redis-commands?
The redis-commands npm package provides a comprehensive list of Redis commands, including their names, arity, flags, and other metadata. It is useful for developers who need to interact with Redis and want to programmatically access command information.
What are redis-commands's main functionalities?
Get All Commands
This feature allows you to retrieve a list of all Redis commands. The `commands.list` property contains an array of all command names.
const commands = require('redis-commands');
console.log(commands.list);
Get Command Details
This feature allows you to get detailed information about a specific Redis command. The `commands.get('set')` method returns an object with details such as arity, flags, and other metadata for the 'set' command.
const commands = require('redis-commands');
console.log(commands.get('set'));
Check Command Existence
This feature allows you to check if a specific Redis command exists. The `commands.exists('get')` method returns true if the command exists and false otherwise.
const commands = require('redis-commands');
console.log(commands.exists('get'));
console.log(commands.exists('nonexistent'));
Get Command Flags
This feature allows you to retrieve the flags associated with a specific Redis command. The `commands.get('set').flags` property returns an array of flags for the 'set' command.
const commands = require('redis-commands');
console.log(commands.get('set').flags);
Other packages similar to redis-commands
ioredis
ioredis is a robust, full-featured Redis client for Node.js. It supports all Redis commands and provides high availability via Redis Sentinel and Cluster. Unlike redis-commands, ioredis is focused on providing a client for interacting with Redis rather than just listing commands.
redis
The redis package is another popular Redis client for Node.js. It supports all Redis commands and provides features like connection pooling and automatic reconnection. Similar to ioredis, it is designed for interacting with Redis servers rather than just listing commands.
node-redis
node-redis is a high-performance Redis client for Node.js. It supports all Redis commands and offers features like pipelining and offline queueing. Like ioredis and redis, it is intended for interacting with Redis servers rather than just listing commands.
Redis Commands
This module exports all the commands that Redis supports.
Install
$ npm install redis-commands
Usage
var commands = require('redis-commands');
.list
is an array contains all the lowercased commands:
commands.list.forEach(function (command) {
console.log(command);
});
.exists()
is used to check if the command exists:
commands.exists('set')
commands.exists('other-command')
.hasFlag()
is used to check if the command has the flag:
commands.hasFlag('set', 'readonly')
.getKeyIndexes()
is used to get the indexes of keys in the command arguments:
commands.getKeyIndexes('set', ['key', 'value'])
commands.getKeyIndexes('mget', ['key1', 'key2'])
Acknowledgment
Thank @Yuan Chuan for the package name. The original redis-commands is renamed to @yuanchuan/redis-commands.